package huoye.shops.huoye.mine.networt;


import android.util.Log;

import com.codeideology.android.http.okhttp.OkHttpUtils;
import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.rpc.BaseJsonRequestCallback;
import com.codeideology.android.utils.StringUtils;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import huoye.shops.base.APIUrls;
import huoye.shops.base.BaseService;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.base.UserManager;
import huoye.shops.base.ZybCallBack;
import huoye.shops.common.model.SMSCoder;
import huoye.shops.huoye.mine.model.AccountList;
import huoye.shops.huoye.mine.model.AddAccountInfo;
import huoye.shops.huoye.mine.model.AuthStateData;
import huoye.shops.huoye.mine.model.ContractData;
import huoye.shops.huoye.mine.model.DividendInfo;
import huoye.shops.huoye.mine.model.EditAccountInfo;
import huoye.shops.huoye.mine.model.EnterPactData;
import huoye.shops.huoye.mine.model.PostDepositRec;
import huoye.shops.huoye.mine.model.QrCodeInfo;
import huoye.shops.huoye.mine.model.ShopDetials;
import huoye.shops.huoye.mine.model.WithdrawHome;
import huoye.shops.huoye.operation.model.Descript;
import huoye.shops.huoye.user.model.UpdateInfo;
import huoye.shops.huoye.user.model.User;
import huoye.shops.utils.StockUtils;


/**
 * Created by user on 2017/7/24.
 */

public class MineService extends BaseService {








    /**
     * 短信验证
     *
     * @param tel
     * @param callback
     */
    public void sendRestPasswordSms(String tel, MineBaseJsonRequestCallback<SMSCoder> callback) {

        //1:微信绑定手机；2：App登录验证 3:App绑定手机）
        Map<String, String> param = new HashMap<>();

        param.put("mobile", tel);
        param.put("sendType", "3");


        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.COMMON_CONFIG.TYPE_COMMON_SMS_CODE_URL))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 提现
     *
     * @param momey
     * @param account
     * @param callback
     */
    public void Withdraw(String momey, String account, MineBaseJsonRequestCallback<User> callback) {

        Map<String, String> param = new HashMap<>();
        setUser(param);
        param.put("money", momey);
        param.put("depositCard", account);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TYPE_MINE_POST_DEPOSIT))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 获取商家提现页面数据
     *
     * @param callback
     */
    public void getDepositIndex(MineBaseJsonRequestCallback<WithdrawHome> callback) {

        Map<String, String> param = new HashMap<>();
        setUser(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TYPE_MINE_POST_DEPOSIT_INDEX))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 收支记录
     *
     * @param mType
     * @param paging
     * @param callback
     */
    public void getRecordPost(int mType, Paging paging, MineBaseJsonRequestCallback<PostDepositRec> callback) {

        Map<String, String> param = new HashMap<>();

        param.put("recordType",mType+"");
        setUserShopList(param, paging);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TYPE_MINE_POST_DEPOSIT_REC))
                .params(param)
                .build().execute(callback);


    }

    /**
     * 管理后台店铺详情
     *
     * @param callback
     */
    public void getShopDetials(MineBaseJsonRequestCallback<ShopDetials> callback) {

        Map<String, String> param = new HashMap<>();

        setUser(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_SHOP_DETIALS))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 新增时获取账户权限列表
     *
     * @param callback
     */
    public void addAccountInfo(MineBaseJsonRequestCallback<AddAccountInfo> callback) {

        Map<String, String> param = new HashMap<>();

        setUser(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_ADD_ACCOUNT_INFO))
                .params(param)
                .build().execute(callback);
    }



   /**
     * 商家获取股东分红列表
     *
    * @param paging
     * @param callback
     */
    public void getPageAllotdetailList(Paging paging,MineBaseJsonRequestCallback<DividendInfo> callback) {

        Map<String, String> param = new HashMap<>();

        setUserShopId(param);
        setPaging(param,paging);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_PAGE_ALLOTDETAIL_LIST))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 编辑时获取账户信息
     *
     * @param editUserId
     * @param callback
     */
    public void editAccountInfo(String editUserId,MineBaseJsonRequestCallback<EditAccountInfo> callback) {

        Map<String, String> param = new HashMap<>();
        param.put("editUserId",editUserId);

        setUser(param);
        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_EDID_ACCOUNT_INFO))
                .params(param)
                .build().execute(callback);
    }

    /**
     * 保存账户（新增或编辑）
     *
     * @param saveUserId
     * @param accountName
     * @param powerStr
     * @param accountState
     * @param codeId
     * @param code
     * @param mobile
     * @param callback
     */
    public void saveAccount(String saveUserId,String accountName, String powerStr, String accountState, String codeId, String code, String mobile, MineBaseJsonRequestCallback<AddAccountInfo> callback) {

        Map<String, String> param = new HashMap<>();



        param.put("saveUserId", saveUserId);
        param.put("accountName", accountName);
        param.put("powerStr", powerStr+",1,3");
        param.put("accountState", accountState);

        if (StringUtils.isNotEmpty(codeId)) {
            param.put("codeId", codeId);
        }

        if (StringUtils.isNotEmpty(code)) {
            param.put("code", code);
        }

        if (StringUtils.isNotEmpty(mobile)) {
            param.put("mobile", mobile);
        }

        setUser(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_SAVE_ACCOUNT))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 上传商家客服二维码
     *
     * @param imagePhone
     * @param mobile
     * @param callback
     */
    public void saveServiceSetting(String mobile,String imagePhone, MineBaseJsonRequestCallback<User> callback) {

        Map<String, String> param = new HashMap<>();

        param.put("mobile", mobile);
        param.put("qrCodeUrl", imagePhone);
        setUserShopId(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_UPLOAD_SHOP_QR_CODE))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 获取商家客服二维码信息
     *
     * @param callback
     */
    public void getShopQrCodeInfo(MineBaseJsonRequestCallback<QrCodeInfo> callback) {

        Map<String, String> param = new HashMap<>();


        setUserShopId(param);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_SHOP_QR_CODE_INFO))
                .params(param)
                .build().execute(callback);
    }



    /**
     * 获取授权状态
     *
     * @param timeStamp
     * @param callback
     */
    public void getAuthState(String timeStamp,MineBaseJsonRequestCallback<AuthStateData> callback) {
        Map<String, String> param = new HashMap<>();
        param.put("timeStamp",timeStamp);
        setUser(param);
        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_AUTH_STATE))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 获取商家管理账户列表
     *
     * @param callback
     */
    public void getAccountList(Paging paging, MineBaseJsonRequestCallback<AccountList> callback) {

        Map<String, String> param = new HashMap<>();

        setUserShopList(param, paging);

        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_ACCOUNT_LIST))
                .params(param)
                .build().execute(callback);
    }

    /**
     * 删除账户
     *
     * @param callback
     */
    public void deleteAccount(String deleteId, MineBaseJsonRequestCallback<AccountList> callback) {

        Map<String, String> param = new HashMap<>();


        param.put("nowUserId", UserManager.getInstance().getUserId());
        param.put("delUserId", deleteId);
        setUserShopId(param);


        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_DELETE_ACCOUNT))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 商家补全合同信息
     *
     * @param contractImgs
     * @param callback
     */
    public void SetContract(List<String> contractImgs, MineBaseJsonRequestCallback<ContractData> callback) {
        Map<String, String> param = new HashMap<>();
        param.put("contractImgs", StockUtils.listToString(contractImgs));
        setUser(param);


        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_SET_CONTRACT))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 获取商家合同信息
     *
     * @param callback
     */
    public void contractInfo(MineBaseJsonRequestCallback<EnterPactData> callback) {
        Map<String, String> param = new HashMap<>();
        setUser(param);
        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_CONTRACT_INFO))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 获取商家个人中心
     *
     * @param callback
     */
    public void getUser(MineBaseJsonRequestCallback<User> callback) {

        Map<String, String> param = new HashMap<>();

        setUserShopId(param);


        OkHttpUtils.getInstance().get()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_SHOP_CENTER_INFO))
                .params(param)
                .build().execute(callback);
    }


    /**
     * 商家商品上传/编辑
     *  @param shopName    //商铺名称
     * @param contactName 联系人
     * @param contactTel  联系电话
     * @param logoImg
     * @param faceImg
     * @param province    省份
     * @param city        城市
     * @param area        地区
     * @param address     详细地址
     * @param shopDes     店铺图文详情集合（[{“imgUrl”:”1/shop/3/info/120638592636.jpg”,”imgDes”:”qweqwe”},{…},…]）
     * @param locations   经纬度
     */
    public void editShopInfo(String shopName, String contactName, String contactTel, String logoImg, List<String> faceImg, String province, String city,
                             String area, String address, List<Descript> shopDes,
                             List<String> locations, MineBaseJsonRequestCallback<User> callback) {
        Map<String, String> param = new HashMap<>();

        Gson gson = new Gson();


        param.put("shopName", shopName);
        param.put("contactName", contactName);
        param.put("contactTel", contactTel);

        param.put("logoImg", logoImg);
        if (faceImg.size() > 0) {
            param.put("faceImg", StockUtils.listToString(faceImg));
        }

        if (locations.size() > 0) {
            param.put("location", StockUtils.listToString(locations));
        }


        String shopDesList = gson.toJson(shopDes);
        if (StringUtils.isNotEmpty(shopDesList))
            param.put("shopDes", shopDesList);


        if (StringUtils.isNotEmpty(province)) {
            param.put("province", province);
        }
        if (StringUtils.isNotEmpty(city)) {
            param.put("city", city);
        }
        if (StringUtils.isNotEmpty(area)) {
            param.put("area", area);
        }
        if (StringUtils.isNotEmpty(address)) {
            param.put("address", address);
        }

        setUser(param);
        OkHttpUtils.getInstance().post()
                .url(getUrl(APIUrls.MINE.TEST_MINE_POST_EDIT_SHOP_INFO))
                .params(param)
                .build().execute(callback);
    }


}


